import java.util.Arrays;

/**
 * Created by Mr.no.
 * User:yangyun
 * Date:2017/8/31
 * Time:23:53
 */
public class Sum01 {
    /**
     * 给定一个整型数组，是否能从中找出其中的两个数使其和为某个指定的值
     */

    public static void main(String[] args){
        int[] A = {1,5,7,3};
        int target = 10;
        hasSum(A ,target);
        System.out.println("是否有这个数"+hasSum(A,target));
    }

    private static boolean hasSum(int[] a, int target) {
        boolean res=false;
        if (a==null|| a.length<2){
             return res;
        }
        Arrays.sort(a);
        int i=0;
        int j=a.length-1;
        while (i<j){
            if (a[i]+a[j]==target){
                res=true;
                break;
            }else {
                if (a[i]+a[j]>target){
                    j--;
                }else {
                    i++;
                }
            }
        }
        return res;
    }
}
